export const CHARTS_COLOR=['#F685A9','#FD8B6D','#FBC251','#DEDC6A','#9EDBDE','#98DAC4','#FFD4D8','#FEC4CC','#DFF6E7','#D0E7F4','#C1D6F1','#778CCD','#E62260','#FBD727','#088F6D','#D83A72','#CDDF63','#02806E','#3BB8B7','#ADD445','#3AB661','#89CCD3','#CA223B','#02ACE5','#77C48A','#F5B22B','#0AA968','#2E4099','#025CA9','#533696','#FEF426','#A01E8C','#6B2891','#EA3353'];
export function getRandomColor(count){
    const result=[];
    const length=CHARTS_COLOR.length;
    if(count<=length){
        const shuffled=[...CHARTS_COLOR]
        for (let i = length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
        }
        return shuffled.slice(0, count);
    }else {
        for (let i = 0; i < count; i++) {
            const randomIndex = Math.floor(Math.random() * length);
            result.push(CHARTS_COLOR[randomIndex]);
        }
        return result;
    }
}

export function hexToHexWithAlpha(hex,alpha){
    hex = hex.replace(/^#/, "");
    if (hex.length !== 6) {
        throw new Error("颜色必须是 6 位十六进制格式，如 #RRGGBB");
    }
    alpha = Math.max(0, Math.min(100, alpha));

    const alphaHex = Math.round((alpha / 100) * 255)
        .toString(16)
        .padStart(2, "0")
        .toUpperCase();
    return `#${hex}${alphaHex}`;
}
